<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .centered-placeholder {
            width: 80%;

            text-align: center;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav main-header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            涂装下线确认
        </div>
    </header>
    <div class="aui-bar aui-bar-nav sub-header"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="white_background">
            <ul class="aui-list aui-form-list">

                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">滑橇号</div>
                        <input type="text" class="aui-input" placeholder="请输入滑橇号" readonly
                            style="width: 80%;font-size: 16px;" id="skiddingCode" />
                    </div>
                </li>
                <li class="aui-list-item" style="background-color: #D7D7D7;">
                    <div class="aui-list-item-inner">
                        <input type="text" class="aui-input centered-placeholder" placeholder="提示消息" readonly
                            style="color: black; font-size: 12px;" id="message" />
                    </div>
                </li>
            </ul>
        </div>
        <div id="table1">

        </div>

    </div>
    <footer>
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin:0 5%;width: 90%;background-color:red !important;color:#f5f5f5;"
            onclick="chooseUnbind()">掉件提报</div>
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin:0 5%;width: 90%;margin-top: 2%;" onclick="offlineConfirm()">确认下线</div>
    </footer>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //光标所在id
    //光标所在id
    var idSelector = "";
    var seqNo = "";
    var arrSave = [];
    var num = 0;
    var mrlnum = 0;
    //初始化查询仓库下拉框
    apiready = function () {
        $("#skiddingCode").val(api.pageParam.skiddingCode)
        seqNo = api.pageParam.seq
        search()
    }
    function search() {
        var arrSave = [];
        var skiddingCode = $("#skiddingCode").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getLineOnOffRecord";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                skiddingCode: skiddingCode,
                seq: seqNo,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    if (list.length > 0) {
                        setTable(list)
                    } else {
                        api.toast({
                            msg: "请先维护治具与滑橇绑定关系！",
                            duration: 3000
                        });
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    function offlineConfirm() {
        api.confirm({
            title: '温馨提示',
            msg: '您确定要完成滑橇号' + api.pageParam.skiddingCode + '的下线确认吗？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                savePlan()
            }
        });
    }
    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += "<div class='white_background'>"
            html += '<ul class="aui-list aui-form-list">'
            html += '<li class="aui-list-item" style="background-color: #03a9f4;">'
            html += '<div class="aui-list-item-inner" >'
            html += '<input type="text" class="aui-input" style="width: 80%;font-size: 14px;" readonly id="skiddingCode" value="' + '层数：' + list[i].level + '&nbsp' + '治具：' + list[i].fixtureCode + '(容量：' + list[i].numTotal + ')' + '">'
            html += '</input>'
            html += '</div>'
            html += '</li>'
            html += '</ul>'
            html += '<div style="background-color:white; width: 100%;white-space: nowrap;overflow: auto;-webkit-overflow-scrolling:touch;">'

            html += '<table class="table" style="width:1050px;" >'

            html += '<tbody style="display:block">'
            html += '<tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">'
            html += '<td algin="center" style="width:30px;"></td>'
            html += '<td algin="center" style="width:50px;">序号</td>'
            html += '<td algin="center" style="width:40px;display: none"></td>'
            html += '<td algin="center" style="width:130px;">规格</td>'
            html += '<td algin="center" style="width:200px;">物料名称</td>'
            html += '<td algin="center" style="width:150px;">产品条码</td>'
            html += '<td algin="center" style="width:130px;">物料编码</td>'
            html += '<td algin="center" style="width:150px;">掉件提报数</td>'
            html += '<td algin="center" style="width:150px;">上线时间</td>'
            html += '</tr>'
            html += '</tbody>'
            html += '<tfoot style="display: block;overflow-y: scroll;">'
            if (list[i].onlineRecordList.length > 0) {
                var onlineRecordListNew = list[i].onlineRecordList
                for (var j = 0; j < list[i].numTotal; j++) {
                    if (j < onlineRecordListNew.length) {
                        var backColor = "";
                        if (parseInt(onlineRecordListNew[j].unQualifyQty) > 0) {
                            backColor = "red"
                        }
                        html += '<tr style="text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;">'
                        html += '<td algin="center" style="width:30px;"><input name="sub" type="checkbox" /></td>'
                        html += '<td algin="center" style="width:50px;background-color:' + backColor + '">' + (j + 1) + '</td>'
                        html += '<td algin="center" style="width:40px;display: none" name="sysid" >' + onlineRecordListNew[j].sysid + '</td>'
                        html += '<td algin="center" style="width:130px;background-color:' + backColor + '" name="drawing">' + onlineRecordListNew[j].drawing + '</td>'
                        html += '<td algin="center" style="width:200px;background-color:' + backColor + '" name="mrlName">' + onlineRecordListNew[j].mrlName + '</td>'
                        html += '<td algin="center" style="width:150px;background-color:' + backColor + '" name="produBarcode" >' + onlineRecordListNew[j].produBarcode + '</td>'
                        html += '<td algin="center" style="width:130px;background-color:' + backColor + '" name="mrlCode">' + onlineRecordListNew[j].mrlCode + '</td>'
                        html += '<td algin="center" style="width:150px;background-color:' + backColor + '" name="unQualifyQty">' + onlineRecordListNew[j].unQualifyQty + '</td>'
                        html += '<td algin="center" style="width:150px;background-color:' + backColor + '">' + onlineRecordListNew[j].onlineDate + '</td>'
                        html += '</tr>'
                    } else {
                        html += '<tr style="text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;">'
                        html += '<td algin="center" style="width:30px;"><input name="sub" type="checkbox" /></td>'
                        html += '<td algin="center" style="width:50px;">' + (j + 1) + '</td>'
                        html += '<td algin="center" style="width:40px;display: none" name="sysid" >' + '</td>'
                        html += '<td algin="center" style="width:130px;" name="drawing">' + '</td>'
                        html += '<td algin="center" style="width:200px;" name="mrlName">' + '</td>'
                        html += '<td algin="center" style="width:150px;" name="produBarcode">' + '</td>'
                        html += '<td algin="center" style="width:130px;" name="mrlCode">' + '</td>'
                        html += '<td algin="center" style="width:150px;" name="unQualifyQty">' + '</td>'
                        html += '<td algin="center" style="width:150px;">' + '</td>'
                        html += '</tr>'
                    }
                }
            } else {
                for (var j = 0; j < list[i].numTotal; j++) {
                    html += '<tr style="text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;">'
                    html += '<td algin="center" style="width:30px;"><input name="sub" type="checkbox" /></td>'
                    html += '<td algin="center" style="width:50px;">' + (j + 1) + '</td>'
                    html += '<td algin="center" style="width:40px;display: none" name="sysid" >' + '</td>'
                    html += '<td algin="center" style="width:130px;" name="drawing">' + '</td>'
                    html += '<td algin="center" style="width:200px;" name="mrlName">' + '</td>'
                    html += '<td algin="center" style="width:150px;" name="produBarcode">' + '</td>'
                    html += '<td algin="center" style="width:130px;" name="mrlCode">' + '</td>'
                    html += '<td algin="center" style="width:150px;" name="unQualifyQty">' + '</td>'
                    html += '<td algin="center" style="width:150px;">' + '</td>'
                    html += '</tr>'
                }
            }
            html += '</tfoot>'
            html += '</table>'
            html += '</div>'
            html += '</div>'
            $api.html($api.byId("table1"), html);
        }
    };

    function savePlan() {
        var skiddingCode = $("#skiddingCode").val()
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveOfflineConfirm";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                seq: seqNo,
                skiddingCode: skiddingCode,
                ZSType: 'seq',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    api.toast({
                        msg: "下线成功",
                        duration: 3000
                    });
                    api.closeWin()
                    api.execScript({
                        name: api.pageParam.name,
                        script: 'search()'
                    });
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function chooseUnbind() {
        var produBarcodeCheck = "";
        var mrlCodeCheck = "";
        var sysidCheck = ""
        var unQualifyQtyCheck = "";
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var flag = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            sysidCheck = row.find("[name='sysid']").html();
            produBarcodeCheck = row.find("[name='produBarcode']").html();
            mrlCodeCheck = row.find("[name='mrlCode']").html();
            unQualifyQtyCheck = row.find("[name='unQualifyQty']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        if (sysidCheck == "" || sysidCheck == null || sysidCheck == undefined) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        if (unQualifyQtyCheck != "") {
            if (parseInt(unQualifyQtyCheck) > 0) {
                api.toast({
                    msg: '该产品条码已经进行过掉件提报！',
                    duration: 3000
                });
                return;
            }
        }
        api.confirm({
            title: '温馨提示',
            msg: '您确定要对' + produBarcodeCheck + '进行掉件提报吗？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                var skiddingCode = $("#skiddingCode").val()
                var un = localStorage.getItem('un');
                var serverUrl = localStorage.getItem('serverUrl');
                var url = serverUrl + "/app/saveUnqualifiedReportingSeq";
                var data = {
                    values: { ////以表单方式提交参数（JSON对象）
                        skiddingCode: skiddingCode,
                        produBarcode: produBarcodeCheck,
                        mrlCode: mrlCodeCheck,
                        seq: seqNo,
                        sysid: sysidCheck,
                        un: un
                    }
                };
                api.ajax({
                    url: url,
                    method: 'post',
                    dataType: 'json',
                    timeout: 300,
                    returnAll: false,
                    data: data
                }, function (ret, err) {
                    if (ret) {
                        var data = JSON.stringify(ret);
                        var myobj = eval("(" + data + ")");
                        if (myobj.code == '0') {
                            api.toast({
                                msg: "提报成功！",
                                duration: 3000
                            });
                            $("#message").val("提报成功")
                            search()
                        } else {
                            api.toast({
                                msg: myobj.message,
                                duration: 3000
                            });
                            $("#message").val(myobj.message)
                        }
                    }
                });
            }
        });



    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>